package com.caiyi.financial.nirvana.sms.service;

import com.caiyi.financial.nirvana.sms.base.service.BaseService;
import com.caiyi.financial.nirvana.sms.entity.SmsGatewayRecharge;
import com.caiyi.financial.nirvana.sms.mapper.SmsGatewayRechargeMapper;
import com.caiyi.financial.nirvana.sms.querybean.GatewayRechargeQueryBean;
import com.caiyi.financial.nirvana.sms.querybean.PageBean;
import com.caiyi.financial.nirvana.sms.vo.SmsGatewayRechargeVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SmsGatewayRechargeService extends BaseService<SmsGatewayRecharge> {
    @Autowired
    private SmsGatewayRechargeMapper smsGatewayRechargeMapper;

    public int addGatewayRecharge(SmsGatewayRecharge smsGatewayRecharge) {
        smsGatewayRecharge.setRechargeTime(new Date());
        int insertCount = this.insertByEntitySelective(smsGatewayRecharge);
        return insertCount;
    }

    public int deleteGatewayRecharge(Integer id) {
        SmsGatewayRecharge smsGatewayRecharge = new SmsGatewayRecharge();
        smsGatewayRecharge.setId(id);
        int deleteCount = this.deleteByPrimaryKey(smsGatewayRecharge);
        logger.info("deleteByGatewayRechargeId id {}", id);
        return deleteCount;
    }

    public int updateGatewayRecharge(SmsGatewayRecharge smsGatewayRecharge) {
        smsGatewayRecharge.setRechargeTime(new Date());
        int updateCount = this.updateByEntitySelective(smsGatewayRecharge);
        return updateCount;
    }

    public PageBean<SmsGatewayRechargeVo> getGatewayRechargeByParams(GatewayRechargeQueryBean bean) {
        PageHelper.startPage(bean.getPageNum(), bean.getPageSize());
        List<SmsGatewayRechargeVo> list = smsGatewayRechargeMapper.selectGatewayRechargeListByParams(bean);
        PageBean<SmsGatewayRechargeVo> pageBean = new PageBean<>(list);
        return pageBean;
    }
}
